package com.hqyj.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description 主题交换机的配置，优点：，路由地址是模糊匹配配置
 * @Autor 伍军
 * @Date 2022/10/19 9:11
 * @Version 1.0
 **/
@Configuration
public class MqTopicConfig {

    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    //创建队列topicOne
    @Bean
    public Queue topicOne(){
        return new Queue("topic_one",true);
    }
    //创建队列topicTwo
    @Bean
    public Queue topicTwo(){
        return new Queue("topic_two",true);
    }
    //创建队列topicThee
    @Bean
    public Queue topicThree(){
        return new Queue("topic_three",true);
    }

    //创建一个主题交换机
    @Bean
    public TopicExchange createTopicExange(){
        return new TopicExchange("createTopicExange");
    }

    @Bean
    public Binding bindQueueAntTopicExange(){
        //* 匹配一个单词， #匹配多个单词
        return BindingBuilder.bind(topicOne()).to(createTopicExange()).with("topic.#");
    }
    @Bean
    public Binding bindQueueAntTopicExange01(){
        //* 匹配一个单词， #匹配多个单词
        return BindingBuilder.bind(topicTwo()).to(createTopicExange()).with("topic.#");
    }
    @Bean
    public Binding bindQueueAntTopicExange02(){
        //* 匹配一个单词， #匹配多个单词
        return BindingBuilder.bind(topicThree()).to(createTopicExange()).with("topic.#");
    }

}
